﻿<?php

require_once '../include/common.inc.php';
require_once '../include/upfile.class.php';

if (!checkAdmin()) {
    header("LOCATION:index.php");
    exit;
}


$category_arr=array("1"=>"Jans<sup>2</sup>en_Furniture","37"=>"Studio Globe Wernicke","39"=>"Bronzes");

$menu_index = 1;
$page_title = 'JANSEN';
$guide_message = 'Product | Delete Products By Category';
$ppp = 30;
$page_show = '';

//by martin 

getMyParam('cid');
$has_produid= "";


if (is_numeric($cid)&&$cid>0)
 {
    	$aryIn = get_category(0);		
		$str_sub_cateid = GetCategoryTreeIDS($aryIn,$cid,false);		
		$sql = "SELECT product_id FROM product_category WHERE category_id IN(".$str_sub_cateid.");";
        $query = $db->query($sql);
        while($rs1 = $db->fetch_array($query))
		 {
            $tmp_ary[] = $rs1['product_id'];
        }
    
   //############################## just check result ############################
    if (!empty($tmp_ary)) 
	{
        $has_produid = implode(",", $tmp_ary);        
    } 
}

$message ="";
if(trim($has_produid)!="")
{
$sql = "SELECT `id` FROM product where `id` IN(".$has_produid.")";
$query = $db->query($sql);
$sql_all_num = $db->num_rows($query);
$sql_1 = "DELETE FROM `product` where `id` IN (".$has_produid.")";
$sql_2 = "DELETE FROM `product_inventory` WHERE `product_id` IN (".$has_produid.")";
$sql_3 = "DELETE FROM `product_category` WHERE `product_id` IN (".$has_produid.")";
$sql_4 = "DELETE FROM `product_p_setting` where `product_id` IN (".$has_produid.")";
$db->query($sql_1) && $db->query($sql_2) && $db->query($sql_3)&& $db->query($sql_4);
 
 $message =  $sql_all_num." item has beed delete from ".$category_arr[$cid];
}elseif(isset($cid)&&$cid>0)
{
   $message =  " No item in ".$category_arr[$cid];
}


$debug = 1;
debuginfo();

//include_once(JANSEN_ROOT . 'admin/menu_list.php');
require_once PrintEot('a_header');
require_once PrintEot('a_P_deleteProC');
require_once PrintEot('a_footer');

?>